package com.cwz.datasource.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.cwz.core.utils.date.DateUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @program: w-demo
 * @description: mybatis-plus 自动填充
 * @author: Wen
 **/
@Component
public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "deleted", Integer.class, 0);
		this.strictInsertFill(metaObject, "createTime", Date.class, DateUtils.getNowDate());
		this.strictInsertFill(metaObject, "updateTime", Date.class, DateUtils.getNowDate());

	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "updateTime", Date.class, DateUtils.getNowDate());

	}
}
